home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS05.ADF
/
tools
/
whereis.c
Wrap
C/C++ Source or Header
|
1986-01-15
|
4KB
|
184 lines
Posted: 85-12-10 09:56:14 EST Unread
From: techs
Subject: Whereis.c -- find a file on the disk
To: amigados
Text:
/* WHEREIS.C
* a program to search for files on any DOS disk.
*
* Syntax: WHEREIS [optional_root_node] <name-of-file>
*
*/
/* when compiling, current drive must contain include directory */
#include <:include/lattice/stdio.h>
#include <:include/exec/types.h>
#include <:include/libraries/dos.h>
main(argc,argv)
int argc;
char *argv[];
{
if ((argc < 2) || (argc > 3)) {
printf ("WHEREIS - Find a file anywhere on the default drive.\n");
printf ("Syntax: WHEREIS [optional_root_node] file_name_to_find\n");
exit (0);
}
if (argc == 2) /* use default drive, root node */
traverse(":", 1, argv[1]);
else if (last(argv[1]) == ':')
traverse(argv[1], 1, argv[2]); /* user supplied drive name */
else
traverse(argv[1], 2, argv[2]); /* user supplied root node */
}
traverse(head,depth,target)
char head[];
int depth;
char target[];
{
struct FileInfoBlock *info;
long lock;
char temp[100];
if ((lock=Lock(head, SHARED_LOCK))==0) {
printf("Cannot open %s.\n", head);
return(0);
}
/* set up a lock for this node, and set up structure for first entry */
info=(struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),0);
if (info==0) {
printf("Allocate Failed, depth=%ld\n",depth);
printf("Hacker meditation #555-1212\n");
UnLock(lock);
return(0);
}
Examine(lock, info);
/* Examine each entry in this directory. If an entry is itself a */
/* directory, traverse that directory recursivly. */
while (ExNext(lock, info)!= 0) {
strcpy(temp,head);
if (depth>1)
strcat(temp,"/");
strcat(temp,info->fib_FileName);
if (stringcmp(info->fib_FileName,target)==0)
printf("%s\n",temp);
if (info->fib_DirEntryType > 0)
traverse(temp, depth+1, target);
}
UnLock(lock);
FreeMem(info,sizeof(struct FileInfoBlock));
}
strcat(s,t)
char *s,*t;
{
while (*s != '\0')
*s++;
while (*s++=*t++)
;
}
strcpy(s,t)
char *s,*t;
{
while (*s++=*t++)
;
}
stringcmp(s,t)
char *s,*t;
{
short int pcount,
ecount;
char patchar;
pcount = ecount = 0;
while(*s){
switch( *t){
case '\0':
return( -1);
case '\'':
if( ecount == 0){
ecount++;
t++;
}
else if( *s != *t)
return(-1);
else{
s++;
t++;
ecount = 0;
}
break;
case '#':
if( ecount){
if( *s != '#')
return( -1);
else{
s++; t++; ecount = 0;
}
}
else{
pcount++;
t++;
}
break;
case '?':
if( ecount){
if( *s != '?')
return(-1);
else{
s++;
t++;
ecount = 0;
}
}
else if( pcount){
t++;
while(*s && ( *s != *t)){
s++;
}
pcount = 0;
}
else {
t++; s++;
}
break;
default:
if( pcount){
patchar = *t++;
while(*s && ( *s == patchar))
s++;
pcount = 0;
}
else if( *s++ != *t++)
return(-1);
break;
}
}
return(*s - *t);
}
last(s)
char *s;
{
while (*s != '\0')
s++;
return(*--s);
}